package com.ruoyi.OutboundManagement.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.ruoyi.OutboundManagement.domain.vo.WarningVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.OutboundManagement.mapper.DeliveryOperationMapper;
import com.ruoyi.OutboundManagement.domain.DeliveryOperation;
import com.ruoyi.OutboundManagement.service.IDeliveryOperationService;

/**
 * 出库操作Service业务层处理
 *
 * @author admin
 * @date 2024-07-09
 */
@Service
public class DeliveryOperationServiceImpl implements IDeliveryOperationService {
    @Autowired
    private DeliveryOperationMapper deliveryOperationMapper;

    /**
     * 新增出库操作
     *
     * @param deliveryOperation 出库操作
     * @return 结果
     */
    @Override
    public int insertDeliveryOperation(DeliveryOperation deliveryOperation) {
        String storageStatus = deliveryOperation.getStorageStatus();
        if (storageStatus != null && storageStatus.equals("2")) {
            deliveryOperation.setTotalAmount(null);
        }
        return deliveryOperationMapper.insertDeliveryOperation(deliveryOperation);
    }


    /**
     * 查询出库操作列表
     *
     * @param materialIds 出库操作
     * @return 出库操作
     */
    @Override
    public List<DeliveryOperation> selectDeliveryOperationList(List<Long> materialIds, String materialName) {
        return deliveryOperationMapper.selectDeliveryOperationList(materialIds, materialName);
    }

    @Override
    public List<DeliveryOperation> selectLingLiao(String shippingType) {
        return deliveryOperationMapper.selectLingLiao(shippingType);
    }

    @Override
    public List<DeliveryOperation> selectTuiHuo(String shippingType) {
        return deliveryOperationMapper.selectTuiHuo(shippingType);
    }

    @Override
    public List<DeliveryOperation> selectXiaoShou(String shippingType) {
        return deliveryOperationMapper.selectXiaoShou(shippingType);
    }

    @Override
    public List<DeliveryOperation> selectWaiCai(String shippingType) {
        return deliveryOperationMapper.selectWaiCai(shippingType);
    }


    /**
     * 批量删除出库操作
     *
     * @param deliveryIds 需要删除的出库操作主键
     * @return 结果
     */
    @Override
    public int deleteDeliveryOperationByDeliveryIds(Long[] deliveryIds) {
        return deliveryOperationMapper.deleteDeliveryOperationByDeliveryIds(deliveryIds);
    }

    /**
     * 删除出库操作信息
     *
     * @param deliveryId 出库操作主键
     * @return 结果
     */
    @Override
    public int deleteDeliveryOperationByDeliveryId(Long deliveryId) {
        return deliveryOperationMapper.deleteDeliveryOperationByDeliveryId(deliveryId);
    }


    /**
     * 查询质检列表
     *
     * @param zhijian 列表查询
     * @return 结果
     */
    @Override
    public List<DeliveryOperation> findByZhijianList(List<String> zhijian, String libraryType, String shippingType, String materialName, String createUser, String storageStatus) {
        // 这里可以添加一些额外的业务逻辑，比如验证zhijianList是否为空等
        // 但在这个简单的示例中，我们直接调用仓库方法
        return deliveryOperationMapper.findByZhijianList(zhijian, libraryType, shippingType, materialName, createUser, storageStatus); // 注意：这个方法名可能需要你根据实际的仓库接口来调整
    }


    /**
     * 修改质检操作
     *
     * @param deliveryOperation 出库操作
     * @return 结果
     */
    @Override
    public int updateDeliveryOperation(DeliveryOperation deliveryOperation) {
        return deliveryOperationMapper.updateDeliveryOperation(deliveryOperation);
    }


    /**
     * 修改出库操作
     *
     * @param deliveryOperation 出库操作
     * @return 结果
     */
    @Override
    public int updateDeliveryChuKu(DeliveryOperation deliveryOperation) {

        return deliveryOperationMapper.updateDeliveryChuKu(deliveryOperation);
    }

        /**
         * 修改入库数量操作
         *
         * @param deliveryOperation 出库操作
         * @return 结果
         */
    @Override
    public int updateDeliveryRu(DeliveryOperation deliveryOperation) {
        return deliveryOperationMapper.updateDeliveryRu(deliveryOperation);
    }


    /**
     * 修改出库数量操作
     *
     * @param deliveryOperation 出库操作
     * @return 结果
     */
    @Override
    public int updateDeliveryChu(DeliveryOperation deliveryOperation) {
        return deliveryOperationMapper.updateDeliveryChu(deliveryOperation);
    }

    @Override
    public int XiuGaiChu(DeliveryOperation deliveryOperation) {
        return deliveryOperationMapper.XiuGaiChu(deliveryOperation);
    }

    @Override
    public List<DeliveryOperation> selectRuTotal(DeliveryOperation deliveryOperation) {
        return deliveryOperationMapper.selectRuTotal(deliveryOperation);
    }

    @Override
    public List<WarningVO> selectWarning(WarningVO warningVO) {
        return deliveryOperationMapper.selectWarning(warningVO);
    }


}